package com.mdp.workflow.bus.candidate.strategy;

import cn.hutool.core.lang.Assert;
import com.mdp.core.utils.CollectionUtils;
import com.mdp.core.utils.StrUtils;
import com.mdp.safe.client.entity.Dept;
import com.mdp.workflow.bus.candidate.TaskCandidateStrategy;
import com.mdp.workflow.client.service.WfSysUserService;
import com.mdp.workflow.comm.dict.CandidateStrategy;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;


/**
 * 部门的负责人 {@link TaskCandidateStrategy} 实现类
 *
 * @author kyle
 *@author 唛盟开源 9哥
 */
@Component
public class DeptManagerStrategy implements TaskCandidateStrategy {

    @Autowired
    WfSysUserService wfSysUserService;

    @Override
    public com.mdp.workflow.comm.dict.CandidateStrategy getStrategy() {
        return CandidateStrategy.DEPT_MANAGER;
    }

    @Override
    public void validateParam(String param) {
        Assert.notNull(param,"部门编号不能为空，多个以逗号分隔");

    }

    @Override
    public Set<String> calculateUsers(DelegateExecution execution, String param) {
        List<String> depptids=StrUtils.splitToString(param,",");
        List<Dept> depts=wfSysUserService.selectDeptListByDeptids(depptids);
        return CollectionUtils.convertSet(depts,Dept::getManager);
    }

}